// import axios from 'axios'

let departmentId;

const getSysDepartmentTree = async () => {
    return await new Promise((resolve, reject) => {
        axios.get('/sys/department/departmentTree').then(res => {
            resolve(res.data.data);
        }).catch(err => {
            reject(err);
        });
    });
}

const getDepartmentTree = async () => {
  return await new Promise((resolve, reject) => {
    axios.get("/index/department/getDepartmentTree", {}).then(res => {
      resolve(res.data.data)
    }).catch(err => {
      reject(err)
    })
  })
}

const createDepartment = async (params) => {
  return await new Promise((resolve, reject) => {
    axios.post("/index/department/createDepartment", params).then(res => {
      resolve(res)
    }).catch(err => {
      reject(err)
    })
  })
}

const getDepartmentDetail = async (id) => {
  return await new Promise((resolve, reject) => {
    axios.get("/index/department/selectEditData?id=" + id, {}).then(res => {
      resolve(res.data.data);
    }).catch(err => {
      reject(err);
    })
  })
}

const editDepartmentData = async (params) => {
  return await new Promise((resolve, reject) => {
    axios.post("/index/department/editDepartmentData", params).then(res => {
      resolve(res);
    }).catch(err => {
      reject(err);
    })
  })
}

const delDepartmentData = async (params) => {
  return await new Promise((resolve, reject) => {
    axios.post("/index/department/del", params).then(res => {
      resolve(res);
    }).catch(err => {
      reject(err);
    })
  })
}

const getRightDepartmentData = async (params) => {
  return await new Promise((resolve, reject) => {
    axios.get("/index/department/selectRightDepartmentData", params).then(res => {
      resolve(res.data.data);
    }).catch(err => {
      reject(err);
    })
  })
}

const moveSite = async (params) => {
  return await new Promise((resolve, reject) => {
    axios.post("/index/department/moveSite", params).then(res => {
      resolve(res);
    }).catch(err => {
      reject(err);
    })
  })
}

const getDepartmentUserList = async (params) => {
    departmentId = params.params.departmentId
    return await new Promise((resolve, reject) => {
        axios.get('/index/department/getDepartmentUserList', params).then(res => {
            resolve(res.data.data)
        }).catch(err => {
            reject(err)
        })
    })
}

const getNoInDepartmentUserList = async (params) => {
    return await new Promise((resolve, reject) => {
        axios.get('/index/department/getNoInDepartmentUserList', params).then(res => {
            resolve(res.data.data)
        }).catch(err => {reject(err)})
    })
}

const setUserIntoDepartment = async (params) => {
    params.departmentId = departmentId
    return await new Promise((resolve, reject) => {
        axios.post('/index/department/setUserIntoDepartment', params).then(res => {
            resolve(res)
        }).catch(err => {reject(err)})
    })
}

const delDepartmentUser = async (params) => {
    params.departmentId = departmentId
    return await new Promise((resolve, reject) => {
        axios.post('/index/department/delDepartmentUser', params).then(res => {
            resolve(res)
        }).catch(err => {reject(err)})
    })
}

export default {
  getSysDepartmentTree,
  getDepartmentTree,
  createDepartment,
  getDepartmentDetail,
  editDepartmentData,
  delDepartmentData,
  getRightDepartmentData,
  moveSite,
  getDepartmentUserList,
  getNoInDepartmentUserList,
  setUserIntoDepartment,
  delDepartmentUser
}
